$(".share").on("click",function(){
	$(".shade").css("display","block");
})

//关闭按钮
$(".close").on("click",function(){
	$(this).parent().parent().css("display","none");
})

$(".open").on("click",function(){
	$(this).parent().parent().css("display","none");
	$(".welcome2").css("display","block");
})

//点击“我要入席”
var a=1;
$(".welcome .text div").eq(1).on("click",function(){
	$(".welcome").css("display","none");
	$(".seatWeb .share").css("display","none");
	$(".seatWeb .number").css("display","block");
	$(".seatWeb .number").find("span").text(a);
})

//页面跳转
function link(){
	$(".welcome .text div").eq(-2).on("click",function(){
		location.href = "huojianmingdan.html";
	})
	
	$(".welcome .text div").last().on("click",function(){
		location.href = "entrance.html";
	})
}
link();

//添加桌子
function addDesk(i){
	var clone = $(".guest").eq(4).clone(true,true);
	$(clone).find("p").text("第"+i+"席");
	$(".add").before(clone);
	
}


//是否能够坐下
var isSit = false;

var screenW = $(window).width()/2;
var screenH = $(window).height()/2;
var centerclick = true;
var isScale = true;
$(".center p").not(":last").on("click",function(){
	var centerR = $(this).height()/2;
	
	var deskLeft = $(this).offset().left;
	var deskTop = $(this).offset().top;
	
	var disLeft = screenW - centerR-deskLeft;
	var disTop = screenH - deskTop - centerR;
	
	if(centerclick){
		centerclick = false;
		if(isScale){
			isScale = false;
			//桌子放大动画
			$(this).parent().transit({
				x:disLeft,
				y:disTop,
				scale: 1.8,
			}, 1000,function(){
				centerclick = true;
				isSit = true;
				
			})
			$(this).parent().parent().siblings().css("visibility","hidden");
			$(".share").css("display","none");
			$(".number").css("display","none");
			$(".seatWeb h1").css("display","none");
		}else{
			//桌子恢复原来位置
			$(this).parent().transit({
				x:0,
				y:0,
				scale: 1,
				easing: 'linear',
			}, 1000,function(){
				centerclick = true;
				isSit = false;
				$(this).parent().siblings().css("visibility","visiable");
				$(".share").css("display","block");
				$(".seatWeb h1").css("display","block");
				$(".seatWeb .sitDown").css("display","none");
			})
			isScale = true;
		}
	}
})


//获取数据
//1. 新增或更新用户信息      
$.ajax({
	method: "post",
	url:"http://student.bluej.cn/index/wedding/upload_user",
	async:true,
	dataType: "jsonp",
	data:{
		wechat_id:sessionStorage.openId,
		name:sessionStorage.nickName,
		province:sessionStorage.province,
		city:sessionStorage.city,
		head_img:sessionStorage.headImg
	},
	success(res) {
		console.log(res);
	}
});

//2. 新增自己的婚宴 
$.ajax({
	method:"post",
	url:"http://student.bluej.cn/index/wedding/add_wedding",
	async:true,
	dataType:"jsonp",
	data:{
		wechat_id:sessionStorage.openId,
		wedding_name:"",
		wedding_position:"",
		time:new Date(2017/11/11).getTime()
	},
	success(res) {
		console.log(res);
	}
})

//3. 获取婚宴座位   
$.ajax({
	method:"post",
	url:"http://student.bluej.cn/index/wedding/get_wedding",
	async:true,
	dataType:"jsonp",
	data:{
		sponsor_id:11
	},
	success(res) {
		console.log(res);
		$(".host .center .Hone").find("img").attr("src",sessionStorage.headImg);
		$(".seatWeb h1 span").text(sessionStorage.nickName);
		$(".seatWeb h1 span").css("border-bottom","none");
		$(".center .small").on("click",function(){
			if(isSit){	//只有在桌子放大时才可以选择座位
				if($(this).find("img").attr("src")==sessionStorage.headImg){
					alert("这个座位有人了");
					a++;
				}else{
					$(this).find("img").attr("src",sessionStorage.headImg);
					$(".blessing").css("display","block");
					$(".sitDown").css("display","block");
					$(".sitDown p").last().find("span").first().text($(this).parent().text());
					$(".sitDown p").last().find("span").last().text($(this).attr("data-id"));
					$(this).siblings().find("img").attr("src","img/desk.png");
				}
			}
			
		})
	}
})

//4. 参加别人的婚宴    
$.ajax({
	method:"post",
	url:"http://student.bluej.cn/index/wedding/join_wedding",
	async:true,
	dataType:"jsonp",
	data:{
		wechat_id:"sessionStorage.openId",
		sponsor_id:11,
		seats:"",
		time:""
	},
	success(res) {
		console.log(res);
	}
})


//5. 改变自己的座位     
$.ajax({
	method:"post",
	url:"http://student.bluej.cn/index/wedding/change_seats",
	async:true,
	dataType:"jsonp",
	data:{
		wechat_id:"sessionStorage.openId",
		sponsor_id:11,
		seats:"",
	},
	success(res) {
		console.log(res);
		if(res.code == 2){
			//alert(res.msg);
		}
	}
})


//6. 添加六个位置  
$.ajax({
	type:"post",
	url:"http://student.bluej.cn/index/wedding/add_seats",
	async:true,
	dataType:"jsonp",
	data:{
		sponsor_id:11
	},
	success(res){
		console.log(res);
		var i=6;
		$(".add .center p").on("click",function(){
			if(res.code==2){
				alert(res.msg);
			}else{
				addDesk(i);
				i++;
			}
		})
	}
});

$.ajax({
	type:"post",
	url: "http://shuaiphp.com/php/jssdk/configInfo_shuai.php",
	async:true,
	dataType:"json",
	data:{"url":location.href.split('#')[0]},
	success:function(res) {
		//console.log(res);
		myjssdk(res);
	}
})

function myjssdk(config) {
	wx.config({
		debug: false,
		appId: config.appId,
		timestamp: config.timestamp,
		nonceStr: config.nonceStr,
		signature: config.signature,
		jsApiList: [
			// 所有要调用的 API 都要加到这个列表中
			"previewImage", 'onMenuShareTimeline', 'getLocation', 'openLocation','startRecord','stopRecord','onVoiceRecordEnd','playVoice','stopVoice','translateVoice','scanQRCode'
		]
	});
	wx.ready(function() {
		// 在这里调用 API
		wx.onMenuShareTimeline({
			title: '张裕金奖白兰地', // 分享标题
			link: '', // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
			imgUrl: 'http://imgsrc.baidu.com/image/c0%3Dshijue1%2C0%2C0%2C294%2C40/sign=971de28cc1ef7609280691dc46b4c9b9/4a36acaf2edda3cce7305e310be93901203f92cf.jpg', // 分享图标
			success: function() {
				// 用户确认分享后执行的回调函数
				alert("分享成功")
			},
			cancel:function() {
				// 用户取消分享后执行的回调函数
				alert("取消分享")
			}
		});
	})
}
